//package cn.wolfcode.wolf2w.business.service.impl;
//
//import cn.wolfcode.wolf2w.business.api.domain.QuestionCollection;
//import cn.wolfcode.wolf2w.business.mapper.QuestionCollectionMapper;
//import cn.wolfcode.wolf2w.business.service.IQuestionCollectionService;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//
//
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import org.springframework.data.domain.Page;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//@Service
//public class QuestionCollectionServiceImpl extends ServiceImpl<QuestionCollectionMapper, QuestionCollection> implements IQuestionCollectionService {
//
//    @Override
//    @Transactional
//    public void collect(Long questionId, Long userId) {
//        // 检查是否已收藏
//        if (isCollected(questionId, userId)) {
//            throw new RuntimeException("已经收藏过该问题");
//        }
//        // 创建收藏记录
////        QuestionCollection collection = QuestionCollectionFactory.create(questionId, userId);
////        save(collection);
//    }
//
//    @Override
//    @Transactional
//    public void uncollect(Long questionId, Long userId) {
//        // 删除收藏记录
//        remove(new LambdaQueryWrapper<QuestionCollection>()
//                .eq(QuestionCollection::getQuestionId, questionId)
//                .eq(QuestionCollection::getUserId, userId));
//    }
//
//    @Override
//    public boolean isCollected(Long questionId, Long userId) {
//        return count(new LambdaQueryWrapper<QuestionCollection>()
//                .eq(QuestionCollection::getQuestionId, questionId)
//                .eq(QuestionCollection::getUserId, userId)) > 0;
//    }
//
//    @Override
//    public Page<QuestionCollection> getUserCollections(Long userId, Integer page, Integer pageSize) {
////        return page(new Page<>(page, pageSize),
////                new LambdaQueryWrapper<QuestionCollection>()
////                        .eq(QuestionCollection::getUserId, userId)
////                        .orderByDesc(QuestionCollection::getCreateTime));
//        return null;
//    }
//
//    @Override
//    public Page<QuestionCollection> getCollectionPage(Integer page, Integer pageSize, Long userId, Long questionId) {
//        LambdaQueryWrapper<QuestionCollection> wrapper = new LambdaQueryWrapper<>();
//        // 如果传入了userId，则按userId查询
//        if (userId != null) {
//            wrapper.eq(QuestionCollection::getUserId, userId);
//        }
//        // 如果传入了questionId，则按questionId查询
//        if (questionId != null) {
//            wrapper.eq(QuestionCollection::getQuestionId, questionId);
//        }
//        // 按创建时间倒序排序
//        wrapper.orderByDesc(QuestionCollection::getCreateTime);
//
////        return page(new Page<>(page, pageSize), wrapper);
//        return null;
//    }
//
//    @Override
//    public int countByUser(Long userId) {
//        return count(new LambdaQueryWrapper<QuestionCollection>()
//                .eq(QuestionCollection::getUserId, userId));
//    }
//
//    @Override
//    public int countByQuestion(Long questionId) {
//        return count(new LambdaQueryWrapper<QuestionCollection>()
//                .eq(QuestionCollection::getQuestionId, questionId));
//    }
//}